package com.zqh.irmadscore.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zqh.irmadscore.model.entity.FailureList;
import com.zqh.irmadscore.service.FailureListService;
import com.zqh.irmadscore.utils.resultUtils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/failureList")
@AllArgsConstructor
@Tag(name = "故障清单")
public class FailureListController {


    private final FailureListService failureListService;

    /*
     * @description: 根据excel获取故障清单
     * @params: [file]
     * @author: zqh
     * @dateTime: 2025/3/31 15:16
     */
    @PostMapping("/getFailureList")
    @Operation(summary = "根据excel获取故障清单")
    public Result<Object> getFailureList(@RequestParam("file") MultipartFile file)
            throws IOException {
       List<FailureList>  list =  failureListService.getFailureList(file);

        return Result.ok(list);
    }

    @GetMapping("/getAllFailureList")
    @Operation(summary = "获取所有故障清单", description = "获取所有故障清单的信息")
    public Result<List<FailureList>> getAllFailureList(){

        List<FailureList> list = failureListService.list();

        return Result.ok(list);
    }

    // 根据故障码获取故障清单
    @GetMapping("/getFailureListByTractName")
    @Operation(summary = "根据监测道名字获取故障信息")
    public Result<List<FailureList>> getFailureListByTractName(@RequestParam String tractName){

        LambdaQueryWrapper<FailureList> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(FailureList::getTractDescription,tractName);
        List<FailureList> list = failureListService.list(queryWrapper);

        return Result.ok(list);
    }


}
